package com.hospital.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hospital.domain.pojo.AdmissionApplication;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AdmissionApplicationMapper extends BaseMapper<AdmissionApplication> {
    
    @Select("SELECT * FROM admission_application WHERE pId = #{pId} ORDER BY aApplyTime DESC")
    List<AdmissionApplication> selectByPatient(Integer pId);
    
    @Select("SELECT * FROM admission_application WHERE depId = #{depId} AND aState = #{state}")
    List<AdmissionApplication> selectByDepartmentAndState(Integer depId, Integer state);
    
    @Select("SELECT * FROM admission_application WHERE aState = #{state} ORDER BY aApplyTime ASC")
    List<AdmissionApplication> selectByState(Integer state);

    // 按医生查询（既包含申请时指定的医生，也包含已审批医生）
    @Select("SELECT * FROM admission_application WHERE dId = #{dId} ORDER BY aApplyTime DESC")
    List<AdmissionApplication> selectByDoctor(Integer dId);

    @Select("SELECT * FROM admission_application WHERE dId = #{dId} AND aState = #{state} ORDER BY aApplyTime DESC")
    List<AdmissionApplication> selectByDoctorAndState(Integer dId, Integer state);
}
